home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
025a
/
prgmchk.zip
/
PARENCHK.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-07-23
|
3KB
|
92 lines
' PARENCHK.BAS - parentheses checker routine - This routine
' compares number of ( vs number of ) per line and prints the line if the
' totals don't agree: If the totals are off but the line ends with a +
' (Rbase continuation symbol) then the routine skips to the next line
' before comparing totals. The routine also checks the sequence of
' opening and closing parentheses and flags the location within a line
' where the number of closing exceeds the number of opening parentheses.
' created 11 July 91; Wm Driskell
CLS
PRINT "Parentheses Checker"
PRINT "-------------------"
PRINT
INPUT "Enter name of file to check: ", ifile$
INPUT "Enter name of file for output: ", ofile$
OPEN "I", #1, ifile$
OPEN "O", #2, ofile$
PRINT #2, "file: "; ifile$
PRINT #2,
PRINT #2, "Line #: total left paren and right paren counts"
PRINT
PRINT "Line #: total left paren and right paren counts"
' setup counters and constants
rpknt = 0 'counters
lpknt = 0
lp$ = "(" 'search strings
rp$ = ")"
lx = 1 'position within text line
rx = 1
' get line and parse for parentheses
DO UNTIL EOF(1)
LINE INPUT #1, a$
lineknt = lineknt + 1
DO
l = INSTR(lx, a$, lp$)
r = INSTR(rx, a$, rp$)
IF l > 0 THEN
lpknt = lpknt + 1
lx = l + 1
END IF
IF r > 0 THEN
rpknt = rpknt + 1
rx = r + 1
END IF
IF rx < lx AND lpknt <= rpknt THEN
PRINT "==>"; lineknt, "**** Too Many Right Parentheses ****"
PRINT #2, "==>"; lineknt, "**** Too Many Right Parentheses ****"
PRINT a$
PRINT #2, a$
PRINT TAB(rx - 1); "^"
PRINT #2, TAB(rx - 1); "^"
END IF
LOOP UNTIL l = 0 AND r = 0
IF lpknt <> rpknt AND RIGHT$(a$, 1) <> "+" THEN
PRINT "==>"; lineknt; ": "; lpknt; rpknt
PRINT a$
PRINT #2, "==>"; lineknt; ": "; lpknt; rpknt
PRINT #2, a$
END IF
lx = 1
rx = 1
LOOP
PRINT
PRINT ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
PRINT
PRINT "total lines processed: "; lineknt
PRINT "total number of parentheses: left - "; lpknt, "right - "; rpknt
PRINT
PRINT "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
PRINT
PRINT #2,
PRINT #2, ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
PRINT #2,
PRINT #2, "total lines processed: "; lineknt
PRINT #2, "total number of parentheses: left -"; lpknt, "right -"; rpknt
PRINT #2,
PRINT #2, ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
PRINT #2,
CLOSE #2
END